﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using AFCEPF.BankApplication.BLL;
using NUnit.Framework;


namespace AFCEPF.BankApplication.Tests
{
    /// <summary>    
    /// L'attribut [TestFixture] indique à NUnit
    /// que cette classe contient des tests..
    /// </summary>
    [TestFixture]
    class Test_GoldAccount
    {
        private Customer _c;

        // indicates if the NegativeBalanceWithdraw event
        // has been fired.
        private bool _overLimitWithdrawFired = false;

        // The two infos that the event will return..
        private Customer _eventCustomer;
        private double _eventBalance;


        [SetUp]
        public void SetUp()
        {
            _c = new Customer("toto");
        }


        [Test]
        public void Test_Event_OverLimitWithdraw()
        {
            AccountBase account = Bank.Instance.Accounts.Create(_c, 
                                                                AccountFactory.MIN_DEPOSIT_FOR_GOLD + 1);
            account.OverLimitWithdraw += OnOverLimitWithdraw;
            account.Withdraw(AccountFactory.MIN_DEPOSIT_FOR_GOLD + account.GetOverdrawnAmount() + 2);

            // Let's check that the NegativeBalanceWithdraw 
            // event has been correctly fired.
            bool result = _overLimitWithdrawFired &&
                            _eventBalance == account.Balance &&
                            _eventCustomer == account.Holder;


            Assert.IsTrue(result);

        }

        void OnOverLimitWithdraw(object sender, AccountEventArgs e)
        {
            _overLimitWithdrawFired = true;
            _eventBalance = e.Balance;
            _eventCustomer = e.Holder;
        }


    }
}
